package com.thp.bigdata.rjoin.findFriends;

import java.io.IOException;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class CommonFriendsStepTwoReducer extends Reducer<Text, Text, Text, Text> {
	@Override
	protected void reduce(Text user_user, Iterable<Text> friends, Context context)
			throws IOException, InterruptedException {
		// 传递进来的数据  <I-K,A> <I-K,B> <I-K,E> ....
		// 新建StringBuffer，用于用户的共同好友们
		StringBuffer stringBuffer = new StringBuffer();
		// 遍历所有好友们，并将这些好友们放在stringBuffer中，以 " " 分隔
		for(Text friend : friends) {
			stringBuffer.append(friend).append(" ");
		}
		// 以好友为key,用户们为value输出到最终的结果
		context.write(user_user, new Text(stringBuffer.toString()));
	}
}
